<template>
  <view class="page">
    <view class="search-bar">
      <view class="search-input">
        <input type="text" v-model="query.keywords" placeholder="请输入谈话主题/内容" />
        <image class="icon-search" src="/static/images/icon_search.png" mode=""></image>
        <view class="search-button" @click="search">搜索</view>
      </view>
    </view>
    <u-dropdown v-if="currPersonType === 1" ref="uDropdown" class="dropdown" :activeColor="dropdown.activeColor"
      :borderBottom="dropdown.borderBottom" :close-on-click-mask="dropdown.mask">
      <u-dropdown-item @change="talkTypeChange" v-model="query.talkType" :title="dropdown.talkTypeTitle"
        :options="dropdown.talkTypeOption"></u-dropdown-item>
      <u-dropdown-item @change="talkSubjectChange" v-model="query.talkSubject" :title="dropdown.talkSubjectTitle"
        :options="dropdown.talkSubjectOption"></u-dropdown-item>
      <u-dropdown-item @change="talkAddressTypeChange" v-model="query.talkAddressType"
        :title="dropdown.talkAddressTypeTitle" :options="dropdown.talkAddressTypeOption"></u-dropdown-item>
    </u-dropdown>
    <scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore">
      <view class="card-list">
        <view v-for="(item, index) in list" :key="index" class="card-item" @click="handleClick(item)">
          <view class="card-desc">谈话主题：</view>
          <view class="card-item-hd">
            <view class="card-title ellipsis">{{item.talkSubjectName}}</view>
            <view class="card-desc">{{currPersonType === 1 ? item.talkTypeName : item.talkAddressTypeName}}</view>
          </view>
          <view class="card-item-bd">
            <view class="card-title">谈话内容：</view>
            <view class="card-desc multiple-ellipsis">{{item.talkContent}}</view>
          </view>
          <view class="card-item-ft">
            <view class="card-time">{{item.createTime}}</view>
            <view v-if="hasPermission('misAssistantTalk_rate') && item.hasRate" class="card-action"
              @click.stop="navTo('rateForm?talkId='+item.id)">学生反馈</view>
            <view v-if="hasPermission('misAssistantTalk_feedback') && item.hasFeedback" class="card-action"
              @click.stop="navTo('feedbackForm?talkId='+item.id)">
              辅导员回复({{item.feedbackCnt}})</view>
          </view>
        </view>
      </view>

      <!-- <view class="uni-list" v-for="(item, index) in list" :key="index" style="margin-top: 5rpx;margin-bottom: 5rpx;"
        @click="handleClick(item)">
        <view v-if="currPersonType===1">
          <u-row gutter="16" style="margin-top: 20rpx;">
            <u-col span="9"
              style="word-break:break-all;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-weight:bold">
              {{item.talkSubjectName}}
            </u-col>
            <u-col span="3" style="text-align: right;">
              <view style="text-align: right;color: gray;margin-right: 10rpx;">
                {{item.talkTypeName}}
              </view>
            </u-col>
          </u-row>
          <u-row gutter="16" style="margin-top: 20rpx;">
            <u-col span="12"
              style="word-break:break-all;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;color:gray">
              {{item.talkContent}}
            </u-col>
          </u-row>
          <u-row gutter="16" style="margin-top: 20rpx;margin-bottom: 10rpx;">
            <u-col span="6">
              <view style="text-align: left;color: gray;">
                {{item.createTime}}
              </view>
            </u-col>
            <u-col span="6" style="text-align: right;">
              <u-button size="mini" shape="circle" plain type="primary" @click="navTo('rateForm?talkId='+item.id)"
                v-if="hasPermission('misAssistantTalk_rate') && item.hasRate">学生反馈</u-button>
              <u-button size="mini" shape="circle" plain type="primary" @click="navTo('feedbackForm?talkId='+item.id)"
                v-if="hasPermission('misAssistantTalk_feedback') && item.hasFeedback">
                <slot>
                  辅导员回复({{item.feedbackCnt}})
                </slot>
              </u-button>
            </u-col>
          </u-row>
        </view>
        <view v-else>
          <u-row gutter="16" style="margin-top: 20rpx;">
            <u-col span="9"
              style="word-break:break-all;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;font-weight:bold">
              {{item.talkTime}}
            </u-col>
            <u-col span="3" style="text-align: right;">
              <view style="text-align: right;color: gray;margin-right: 10rpx;">
                {{item.talkAddressTypeName}}
              </view>
            </u-col>
          </u-row>
          <u-row gutter="16" style="margin-top: 20rpx;">
            <u-col span="12"
              style="word-break:break-all;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;color:gray">
              {{item.talkContent}}
            </u-col>
          </u-row>
          <u-row gutter="16" style="margin-top: 20rpx;margin-bottom: 10rpx;">
            <u-col span="6">
              <view style="text-align: left;color: gray;">
                {{item.createTime}}
              </view>
            </u-col>
            <u-col span="6" style="text-align: right;">
              <u-button size="mini" shape="circle" plain type="warning" @click="navTo('rateForm?talkId='+item.id)"
                v-if="hasPermission('misAssistantTalk_rate') && item.hasRate">学生反馈</u-button>
              <u-button size="mini" shape="circle" plain type="warning" @click="navTo('feedbackForm?talkId='+item.id)"
                v-if="hasPermission('misAssistantTalk_feedback') && item.hasFeedback">
                <slot>
                  辅导员回复({{item.feedbackCnt}})
                </slot>
              </u-button>
            </u-col>
          </u-row>
        </view>
      </view> -->
      <u-loadmore class="loadmore" :status="loadStatus"></u-loadmore>
    </scroll-view>
    <!-- <view class="btn-plus" @click="navTo('form')" v-if="hasPermission('misAssistantTalk_add')">
      <u-icon name="plus-circle-fill" size="90" color="#3d87ff"></u-icon>
    </view> -->
    <view v-if="hasPermission('misAssistantTalk_add')" class="add-btn" @click="navTo('form')">
      <image src="/static/images/icon_add_message.png" mode=""></image>
    </view>
  </view>
</template>
<script>
  import $time from '@/common/time.js';
  export default {
    data() {
      return {
        query: {
          current: 1,
          size: 10,
          keywords: '',
          talkBeginDate: '',
          talkBeginDate: '',
          talkType: '',
          talkSubject: '',
          talkAddressType: '',
          createUser: ''
        },
        list: [],
        pages: 0,
        loadStatus: 'loadmore',
        options: [],
        headStyle: {
          fontWeight: 'bold',
          color: '#606266',
          margin: '16rpx'
        },
        statusList: [],
        swiperCurrent: 0,
        currPersonType: null,
        dropdown: {
          borderBottom: false,
          activeColor: '#3989FC',
          mask: true,
          talkTypeOption: [],
          talkTypeTitle: '谈话方式',
          talkSubjectOption: [],
          talkSubjectTitle: '谈话类型',
          talkAddressTypeOption: [],
          talkAddressTypeTitle: '谈话地点',
        },
      };
    },
    onLoad(params) {
      if (params.createUser) {
        this.query.createUser = params.createUser;
      }
      this.currPersonType = this.vuex_personType;
      this.loadList();
      this.initTalkAddressType();
      this.initTalkSubject();
      this.initTalkType();
    },
    computed: {

    },
    methods: {
      navTo(url) {
        uni.navigateTo({
          url: url
        });
      },
      search(value) {
        this.list = [];
        this.query.current = 0;
        this.loadList();
      },
      loadList() {
        this.$u.api.mis.misAssistantTalk.list(this.query).then(res => {
          if (!res.data.records || res.data.records.length == 0) {
            this.loadStatus = "nomore";
            return;
          }
          res.data.records.forEach((item) => {
            item.show = false;
          })
          this.list = this.list.concat(res.data.records);
          this.pages = res.pages;
          this.query.current = res.data.current;
          this.query.size = res.data.size;
          this.loadStatus = "loadmore";
        });
      },
      loadMore() {
        this.loadStatus = "loading";
        setTimeout(() => {
          this.query.current += 1;
          this.loadList();
        }, 100);
      },
      handleClick(row) {
        this.navTo('form?id=' + row.id);
      },
      initTalkType() {
        this.$u.api.dictBizData({
          code: 'mis_talk_type'
        }).then(res => {
          let detaiList = [];
          let detailJson = {
            'label': '全部',
            'value': ''
          }
          detaiList.push(detailJson)
          res.data.forEach((item) => {
            detaiList.push({
              'label': item.dictValue,
              'value': item.dictKey
            });
          })
          this.dropdown.talkTypeOption = detaiList;
        });
      },
      initTalkAddressType() {
        this.$u.api.dictBizData({
          code: 'mis_talk_address'
        }).then(res => {
          let detaiList = [];
          let detailJson = {
            'label': '全部',
            'value': ''
          }
          detaiList.push(detailJson)
          res.data.forEach((item) => {
            detaiList.push({
              'label': item.dictValue,
              'value': item.dictKey
            });
          })
          this.dropdown.talkAddressTypeOption = detaiList;
        });
      },
      initTalkSubject() {
        this.$u.api.dictBizData({
          code: 'mis_talk_subject'
        }).then(res => {
          let detaiList = [];
          let detailJson = {
            'label': '全部',
            'value': ''
          }
          detaiList.push(detailJson)
          res.data.forEach((item) => {
            detaiList.push({
              'label': item.dictValue,
              'value': item.dictKey
            });
          })
          this.dropdown.talkSubjectOption = detaiList;
        });
      },
      talkTypeChange(index) {
        this.list = [];
        this.query.current = 0;
        this.query.talkType = index
        this.dropdown.talkTypeTitle = (index === '' ? '谈话方式' : this.getOptionLabel(this.dropdown.talkTypeOption,
          index));
        this.loadList()
      },
      talkAddressTypeChange(index) {
        this.list = [];
        this.query.current = 0;
        this.query.talkAddressType = index
        this.dropdown.talkAddressTypeTitle = (index === '' ? '谈话地点' : this.getOptionLabel(this.dropdown
          .talkAddressTypeOption, index));
        this.loadList()
      },
      talkSubjectChange(index) {
        this.list = [];
        this.query.current = 0;
        this.query.talkSubject = index
        this.dropdown.talkSubjectTitle = (index === '' ? '谈话类型' : this.getOptionLabel(this.dropdown.talkSubjectOption,
          index));
        this.loadList()
      },
    }
  };
</script>
<style lang="scss">
  .page {
    position: relative;
    background: #F7F7F7;
  }

  .search-bar {
    display: flex;
    align-items: center;
    padding: 16rpx 32rpx;
    background: #fff;
  }

  .search-input {
    position: relative;
    width: 100%;
    height: 64rpx;
    border-radius: 32rpx;
    background: #F7F7F7;
    overflow: hidden;

    input {
      width: 100%;
      height: 64rpx;
      border: 0;
      padding: 0 144rpx 0 64rpx;
      outline: 0;
      line-height: 64rpx;
      font-size: 24rpx;
      font-weight: 500;
      color: #999;
      background: transparent;
    }

    .icon-search {
      position: absolute;
      top: 21rpx;
      left: 21rpx;
      width: 22rpx;
      height: 22rpx;
    }

    .search-button {
      position: absolute;
      top: 0;
      right: 0;
      width: 144rpx;
      border-radius: 32rpx;
      line-height: 64rpx;
      text-align: center;
      font-size: 24rpx;
      font-weight: 700;
      color: #fff;
      background: #3989FC;
    }
  }

  .dropdown {
    height: 80rpx;
    background: #fff;

    &+.scroll-list {
      height: calc(100vh - var(--window-top) - var(--window-bottom) - 96rpx - 80rpx);
    }
  }

  .scroll-list {
    height: calc(100vh - var(--window-top) - var(--window-bottom) - 96rpx);

    .loadmore {
      padding: 32rpx;
    }
  }

  .card-list {
    display: flex;
    flex-direction: column;
    padding: 24rpx 24rpx 0;
  }

  .card-item {
    border-radius: 8rpx;
    padding: 32rpx;
    margin-bottom: 24rpx;
    background: #fff;
  }

  .card-item-hd {
    margin-top: 32rpx;
  }

  .card-item-bd {
    margin-top: 32rpx;

    .card-title {
      font-size: 28rpx;
    }

    .card-desc {
      font-size: 24rpx;
    }
  }

  .card-item-ft {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24rpx;
  }

  .card-title {
    margin-bottom: 16rpx;
    font-size: 32rpx;
    font-weight: 700;
    color: #333;
  }

  .card-desc {
    font-size: 28rpx;
    font-weight: 500;
    color: #999;
  }

  .card-time {
    font-size: 28rpx;
    color: #ccc;
  }

  .card-action {
    display: inline-block;
    border-radius: 56rpx;
    padding: 0 32rpx;
    line-height: 56rpx;
    font-size: 24rpx;
    font-weight: 500;
    color: #3989FC;
    background: #DEEBFE;
  }

  .add-btn {
    position: absolute;
    right: 32rpx;
    bottom: 288rpx;
    z-index: 99;
    width: 88rpx;
    height: 88rpx;

    image {
      width: 88rpx;
      height: 88rpx;
      vertical-align: top;
    }
  }

  .ellipsis {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .multiple-ellipsis {
    display: -webkit-box;
    word-break: break-all;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
</style>